package kr.hkit.androidcomplete01.chapter06;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class SetParameterEx extends Activity {
	Button mLeftBtn;
	Button mRightBtn;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch06_setparameterex);
		mLeftBtn = (Button) findViewById(R.id.btnLeft);
		mRightBtn = (Button) findViewById(R.id.btnRight);
	}
	
	public void mOnClick(View v){
		switch(v.getId()){
		case R.id.btnLeft:
			setParam(3,1);
			break;
		case R.id.btnRight:
			setParam(1,3);
			break;
		}
	}

	private void setParam(int left, int right) {
		LinearLayout.LayoutParams lParams = (LayoutParams) mLeftBtn.getLayoutParams();
		lParams.weight=left;
		mLeftBtn.setLayoutParams(lParams);
		
		LinearLayout.LayoutParams rParams = (LayoutParams) mRightBtn.getLayoutParams();
		rParams.weight=right;
		mRightBtn.setLayoutParams(rParams);
	}
}
